<?php

namespace App\Admin\Exports\Sheet;

use App\Models\Vocabulary\Vocabulary;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithTitle;
class VocabularySheet implements FromCollection, WithHeadings, WithTitle
{
    public function collection()
    {
        $vocabularys= Vocabulary::query()->with('options')->select([
            'id', 'type', 'category_id', 'click_learn_id', 'item_id','sentence','on_sort','game_type','sentence_id'
        ])->get();
        foreach ($vocabularys as $vocabulary) {
            $vocabularys->vocabular_options=implode(",", $vocabulary->options->pluck('title')->toArray());
            unset($vocabulary->options);
        }
        return $vocabularys;
    }

    public function headings(): array
    {
        return [
            '单元词汇表编号', '类型 1：练习听音选择 2：拼写 3：练习选词填空 4：跟读', '单元编号', '内容/资源编号','练习题音频编号','练习题题干','是否开启排序','游戏类型 1:小火车装货物 2扎气球 3足球打气 4投篮球 5发射小火箭','句子编号','选项'
        ];
    }
    public function title(): string
    {
        return '单元词汇表';
    }
}
